package com.dongdongshop.controller;

import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("seller")
public class SellerController {

    @DubboReference
    private SellerService ss;

    @RequestMapping("show")
    public String show(){
        return "admin/seller_1";
    }

    @RequestMapping("sellerList")
    @ResponseBody
    public Result sellerList(String name,String nickName){
        try {
            List<TbSeller> tbSellers = ss.sellerList(name, nickName);
            return Result.OK().setData(tbSellers);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR);
        }
    }


    @RequestMapping("seller")
    @ResponseBody
    public Result seller(){
        try {
            List<TbSeller> all = ss.getAll();
            return Result.OK().setData(all);
        } catch (Exception e) {
            return Result.response(ResultEnum.ERROR);
        }

    }

    @RequestMapping("audit")
    @ResponseBody
    public Result audit(String[] ids,String status){
        try {
            ss.audit(ids, status);
            return Result.response(ResultEnum.SUCCESS);
        } catch (Exception e) {
            return Result.response(ResultEnum.AUDIT_MESSAGE_ERROER);
        }

    }

}
